package o;

import android.content.Intent;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.application.pkgmanage.model.reserve.ReserveDbInfo;
import com.huawei.appmarket.service.reserve.game.bean.OrderAppInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.epq.e;

public final class efg {
    private static volatile efg ˎ;
    private static final Object ॱ = new Object();
    private final List<ReserveDbInfo> ˏ = new ArrayList();

    private efg() {
        ˊ();
    }

    public static efg ˋ() {
        if (ˎ == null) {
            synchronized (ॱ) {
                if (ˎ == null) {
                    ˎ = new efg();
                }
            }
        }
        return ˎ;
    }

    public synchronized void ˏ(List<OrderAppInfo> list) {
        if (CollectCheck.isEmpty((List) list)) {
            this.ˏ.clear();
            euc.ˊ().ॱ();
            efn.ˊ().ˏ();
            euc.ˊ().ˏ();
        } else {
            ˊ((List) list);
            Collection arrayList = new ArrayList();
            for (OrderAppInfo orderAppInfo : list) {
                if (Logger.ˎ()) {
                    Logger.ˏ("ReserveListSync", "refreshReservedGameList, package:" + orderAppInfo.ˎ());
                }
                ReserveDbInfo ॱ = ॱ(orderAppInfo.ˎ());
                ReserveDbInfo reserveDbInfo = new ReserveDbInfo();
                reserveDbInfo.ˋ(orderAppInfo.ॱ());
                reserveDbInfo.ͺ(orderAppInfo.ʼ());
                reserveDbInfo.ॱ(orderAppInfo.ͺ());
                reserveDbInfo.ˊ(orderAppInfo.ˎ());
                reserveDbInfo.ˏ(orderAppInfo.ʻ());
                reserveDbInfo.ˎ(orderAppInfo.ॱॱ());
                reserveDbInfo.ʽ(orderAppInfo.ʽ());
                reserveDbInfo.c_(orderAppInfo.ᐝ());
                reserveDbInfo.ˊ(orderAppInfo.ˊॱ());
                reserveDbInfo.ˋ(orderAppInfo.ˏॱ());
                reserveDbInfo.ॱॱ(orderAppInfo.ॱˊ());
                reserveDbInfo.ˊॱ(orderAppInfo.ॱᐝ());
                reserveDbInfo.ˊ(orderAppInfo.ˋॱ());
                reserveDbInfo.ॱˊ(orderAppInfo.ʻॱ());
                reserveDbInfo.ˎ(orderAppInfo.ᐝॱ());
                reserveDbInfo.ॱ(orderAppInfo.ॱˎ());
                if (ॱ != null) {
                    reserveDbInfo.ᐝ(ॱ.ʽ());
                    reserveDbInfo.ʼ(ॱ.ˊॱ());
                }
                arrayList.add(reserveDbInfo);
            }
            this.ˏ.clear();
            this.ˏ.addAll(arrayList);
            euc.ˊ().ॱ();
            efn.ˊ().ॱ(this.ˏ);
            euc.ˊ().ˏ();
            dvq.ˊ(ContentManager.getInstant().getContext(), null, 0);
            Intent intent = new Intent();
            intent.setAction(e.ॱ);
            ll.ˏ(ContentManager.getInstant().getContext()).ˋ(intent);
        }
    }

    private synchronized void ˊ(List<OrderAppInfo> list) {
        if (!CollectCheck.isEmpty(this.ˏ)) {
            euc.ˊ().ॱ();
            for (ReserveDbInfo reserveDbInfo : this.ˏ) {
                if (ˊ(list, reserveDbInfo.ˋ()) == null) {
                    efn.ˊ().ॱ(reserveDbInfo.ˋ());
                    Logger.ˎ("ReserveListSync", "invalid reserve:" + reserveDbInfo.ˋ());
                }
            }
            euc.ˊ().ˏ();
        }
    }

    private OrderAppInfo ˊ(List<OrderAppInfo> list, String str) {
        if (!CollectCheck.isEmpty((List) list)) {
            for (OrderAppInfo orderAppInfo : list) {
                if (str.equals(orderAppInfo.ˎ())) {
                    return orderAppInfo;
                }
            }
        }
        return null;
    }

    public synchronized ReserveDbInfo ॱ(String str) {
        ReserveDbInfo reserveDbInfo;
        if (!CollectCheck.isEmpty(this.ˏ)) {
            for (ReserveDbInfo reserveDbInfo2 : this.ˏ) {
                if (str.equals(reserveDbInfo2.ˋ())) {
                    break;
                }
            }
        }
        reserveDbInfo2 = null;
        return reserveDbInfo2;
    }

    public synchronized void ˋ(ReserveDbInfo reserveDbInfo) {
        if (reserveDbInfo != null) {
            if (!TextUtils.isEmpty(reserveDbInfo.ˋ())) {
                ReserveDbInfo ॱ = ˋ().ॱ(reserveDbInfo.ˋ());
                if (ॱ != null) {
                    this.ˏ.remove(ॱ);
                }
                this.ˏ.add(reserveDbInfo);
            }
        }
        Logger.e("ReserveListSync", "addReserveGame failed, reserveDbInfo or packageName isEmpty");
    }

    public synchronized void ˏ() {
        if (this.ˏ != null) {
            this.ˏ.clear();
        }
        euc.ˊ().ॱ();
        efn.ˊ().ˏ();
        euc.ˊ().ˏ();
        dvq.ˊ(ContentManager.getInstant().getContext(), null, 0);
    }

    public synchronized List<ReserveDbInfo> ॱ() {
        return new ArrayList(this.ˏ);
    }

    private void ˊ() {
        euc.ˊ().ॱ();
        this.ˏ.clear();
        this.ˏ.addAll(efn.ˊ().ˎ("reserveTime_"));
        euc.ˊ().ˏ();
        Logger.ˎ("ReserveListSync", "reserveDbInfoList read from db:" + this.ˏ.size());
    }

    public synchronized void ˊ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("ReserveListSync", "removeReserveGame failed, packageName isEmpty");
        } else {
            ReserveDbInfo ॱ = ˋ().ॱ(str);
            if (ॱ != null) {
                this.ˏ.remove(ॱ);
                dko o_dko = new dko();
                o_dko.ˏ(ॱ.ˋ().hashCode());
                dkk.ˊ(ContentManager.getInstant().getContext(), o_dko).ॱ();
            } else {
                Logger.e("ReserveListSync", "removeReserveGame, oldDbInfo == null.");
            }
        }
    }

    public synchronized boolean ˏ(String str) {
        boolean z;
        if (TextUtils.isEmpty(str)) {
            z = false;
        } else {
            for (ReserveDbInfo reserveDbInfo : this.ˏ) {
                if (reserveDbInfo != null && str.equals(reserveDbInfo.ˋ())) {
                    z = true;
                    break;
                }
            }
            z = false;
        }
        return z;
    }
}
